import 'package:flutter/material.dart';

class AnimatedWidgetTest extends StatefulWidget {
  const AnimatedWidgetTest({super.key});

  @override
  State<AnimatedWidgetTest> createState() => _AnimatedWidgetTestState();
}

class _AnimatedWidgetTestState extends State<AnimatedWidgetTest> {
  double _padding = 5;
  Duration _duration = Duration(milliseconds: 200);
  double _left = 20;
  Alignment _alignment = Alignment.topRight;
  Color _color = Colors.red;
  double _height = 50;
  TextStyle _textStyle = TextStyle(
    fontSize: 20,
    color: Colors.red,
    fontWeight: FontWeight.w500,
  );
  double _opacity = 1;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        ElevatedButton(
          onLongPress: () {
            setState(() {
              _padding = 20;
            });
          },
          onPressed: () {
            setState(() {
              _padding = 10;
            });
          },
          child: AnimatedPadding(
            duration: _duration,
            padding: EdgeInsets.all(_padding),
            child: Text('animated padding'),
          ),
        ),
        SizedBox(
          height: 100,
          child: Stack(children: [
            AnimatedPositioned(
              left: _left,
              child: ElevatedButton(
                child: Text(' animated positioned'),
                onPressed: () {
                  setState(() {
                    _left = 100;
                  });
                },
              ),
              duration: _duration,
            )
          ]),
        ),
        Container(
          height: 100,
          width: double.infinity,
          child: AnimatedAlign(
            duration: _duration,
            child: ElevatedButton(
              child: Text(' animated align'),
              onPressed: () {
                setState(() {
                  _alignment = Alignment.bottomLeft;
                });
              },
            ),
            alignment: _alignment,
          ),
        ),
        AnimatedContainer(
          duration: _duration,
          child: ElevatedButton(
            child: Text(' animated container'),
            onPressed: () {
              setState(() {
                _color = Colors.blue;
                _height = 100;
              });
            },
          ),
          color: _color,
          height: _height,
        ),
        AnimatedDefaultTextStyle(
          child: GestureDetector(
            child: Text('animated default text style'),
            onTap: () {
              setState(() {
                _textStyle = TextStyle(
                    color: Colors.blue,
                    fontSize: 30,
                    fontWeight: FontWeight.w900);
              });
            },
          ),
          style: _textStyle,
          duration: _duration,
        ),
        AnimatedOpacity(
          opacity: _opacity,
          duration: _duration,
          child: ElevatedButton(
            child: Text('animated opacity'),
            onPressed: () {
              setState(() {
                _opacity = 0.5;
              });
            },
          ),
        ),
      ]
          .map((e) => Container(
                margin: EdgeInsets.only(bottom: 10),
                decoration:
                    BoxDecoration(border: Border.all(color: Colors.red)),
                child: e,
              ))
          .toList(),
    );
  }
}
